<?php
namespace app\bancard\controller;

use think\Db;
use think\facade\Cache;

class Attendancecourse extends Common
{
    protected $attendance_status = [0 => '', 1 => '正常', 2 => '迟到', 3 => '缺卡'];

    //首页
    public function index()
    {


        //取得年级信息
        $grade_info = $this->getGrade()['data'];

        //取得学科信息
        $sub_info = $this->allSubject();

        //取得教师信息
        $teacher_info = $this->getAllTeachers()['data'];


        $this->assign('grade_arr', $grade_info);
        $this->assign('sub_arr', $sub_info);
        $this->assign('teacher_arr', $teacher_info);

        return $this->fetch();

    }

    public function lists()
    {

        $class_id = request()->param('class_id');
        $teacher_id = request()->param('teacher_id');
        $subject_id = request()->param('subject_id');
        $section_num = request()->param('section_num');

        $limit = request()->param('limit');
        $offset = request()->param('offset');
        $start = ($offset - 1) * $limit;

        if (!empty($class_id)) {
            $map[] = ['class_id', '=', $class_id];
        }

        if (!empty($teacher_id)) {
            $map[] = ['teacher_id', '=', $teacher_id];
        }

        if (!empty($subject_id)) {
            $map[] = ['subject_id', '=', $subject_id];
        }

        if (!empty($section_num)) {
            $section_num=intval($section_num);
            $map[] = ['section_num', '=', $section_num];
        }

        if(!empty($map)){
            $count = db('attendance_curr_log')->where($map)->count();
            $result = db('attendance_curr_log')->where($map)->limit($start, $limit)->order('id desc')->select();
        }else{
            $count = db('attendance_curr_log')->count();
            $result = db('attendance_curr_log')->limit($start, $limit)->order('id desc')->select();
        }

        return showTable(0, 'OK', $count, $result, 200);

    }

    //根据grade——ID取得班级列表
    public function classes()
    {

        $data = request()->param();
        $result =$this->getClassesByGradeIds($data['id'])['data'];

        return $result;

    }



}